class TalkMenu extends PIXI.Container {
	constructor(uimanager, items, talker, context, option, callback) {
		super();
		this.uimanager = uimanager;
		this.callback = callback;
		this._itemLength = items.length;

		const talkStyle = new PIXI.TextStyle({
			fontFamily: 'Arial',
			fontSize: 14,
			fontWeight: 'bold',
			fill: ['#201000'],
			wordWrap: true,
			breakWords:true,
			wordWrapWidth: 240,
			lineJoin: 'round',
			dropShadow: true,
			dropShadowColor: '#D0C890',
			dropShadowBlur: 1,
			dropShadowAngle: Math.PI / 6,
			dropShadowDistance: 3,
		});

		// 创建对话框
		const frame = new PIXI.smooth.SmoothGraphics();
		frame.beginFill(0x686028, 1);
		frame.lineStyle({ color: 0x181818, width: 1, alignment: 0 });
		frame.drawRoundedRect(0,0,460,100,50);
		frame.beginFill(0xE0E0C0, 1);
		frame.lineStyle({ color: 0x686028, width: 0, alignment: 0 });
		frame.drawRoundedRect(2,2,460-4,100-4,50);
		frame.endFill();

		frame.position.set(uimanager.realScreen.width - 410, 50);

		// 设置对话位置	
		const richText = new PIXI.Text(context, talkStyle);
		richText.x = 0;
		richText.y = 0;
		richText.resolution = 2;
		richText.position.set(frame.position.x + 30, frame.position.y + 10);

		// 得到talker半身像
		const avater = PIXI.Texture.from(talker.avater);
		const spriteImage = new PIXI.Sprite(avater);
		spriteImage.x = uimanager.realScreen.width - 156;

		// 添加一个对话框容器
		this.addChild(frame);
		this.addChild(richText);	
		this.addChild(spriteImage);

		// 添加menu
		this.menu = new Menu("MENU", 210, 0, 170)
		this.menu.x = uimanager.realScreen.width - 220;
		this.menu.y = 166;
		this.addChild(this.menu);

		for(var i = 0; i < items.length; i++)
			this.menu.addItem(new MenuItem(items[i]));
		
		this.menu.selectedIndex = 0;
		this.uimanager.addChild(this);
	}

	keyDown(key) {
		switch(key) 
		{
			case "up": this.menu.up(); break;
			case "down": this.menu.down(); break;
			case "z":
				this.callback(this.menu.selectedIndex);
				this.uimanager.removeChild(this);
				break;
		}
	}
}
